package com.lbt.javaSE.jianzhioffer;



import java.util.ArrayList;


public class JZ3ArrayList {
    public class ListNode {
         int val;
         ListNode next = null;
         ListNode(int val) {
         this.val = val;
        }
    }

    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        ArrayList<Integer> list=new ArrayList<>();
        while (listNode!=null){
            list.add(listNode.val);
            listNode=listNode.next;
        }
        //将数组传入 list中
        ArrayList<Integer> result=new ArrayList<>();
        int size = list.size()-1;
        for(int i=size;i>=0;i--){
            result.add(list.get(i));
        }
        return  result;
    }
}
